using GameFramework.Network;

namespace LS.UGFUnits
{
    using Unity.VisualScripting;
    
    public class GetNetworkChannel: NetworkUnit
    {
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput Name { get; private set; }
        
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput Channel { get; private set; }

        protected override void Definition()
        {
            base.Definition();
            Name = ValueInput<string>(nameof(Name), string.Empty);
            Channel = ValueOutput<INetworkChannel>(nameof(Channel));
            Requirement(Name, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            string name = flow.GetValue<string>(Name);
            INetworkChannel channel = Target?.GetNetworkChannel(name) ?? null;
            flow.SetValue(Channel, channel);
            return base.In(flow);
        }
    }
}